<template>
  <div class="mg16 flex">
    <apply-left :setpData="setpData"></apply-left>
    <div class="apply_right">
      <div class="apply_root">
        <i class="el-icon-warning" style="color: #0c7ff2; font-size: 14px"></i>
        您的{{ rootData.meetingTitle }}类会议的剩余权限：银牌赞助 : <span>{{ rootData.show }}</span> 个 &nbsp;&nbsp;
        金牌赞助 : <span>{{ rootData.report }}</span>个&nbsp;&nbsp; 钻石赞助 : <span>{{ rootData.diamond
        }}</span>个
        <!-- 金牌赞助 : <span>{{ rootData.gold }}</span>个 &nbsp;&nbsp; -->
      </div>
      <div class="apply_meet_info">
        <h4>会议详情</h4>
        <div class="apply_jg" v-if="setpData.stepExamineOneStatus == 3">
          <i class="el-icon-warning" style="color: #FF6332; font-size: 14px"></i>
          提示:您的赞助申请已驳回，驳回原因：{{ message }}
        </div>
        <div class="meet_content">
          <span class="realitive">
            <img :src="meetingData.meetinginfo.meetingImg" class="img" alt="" />
            <span v-if="meetingData.meetinginfo.meetSponsorType == 3" class="mt_a">A类会议</span>
            <span v-if="meetingData.meetinginfo.meetSponsorType == 2" class="mt_b">B类会议</span>
            <span v-if="meetingData.meetinginfo.meetSponsorType == 1" class="mt_c">C类会议</span>
          </span>
          <div class="content_right">
            <div class="title">
              {{ meetingData.meetinginfo.title }}
            </div>
            <p class="time">
              {{ meetingData.meetinginfo.startTime }}-{{
                meetingData.meetinginfo.videoEndDate
              }}
            </p>
            <p class="content sl2">
              {{ meetingData.meetinginfo.content }}
            </p>
          </div>
        </div>
      </div>
      <div class="apply_body">
        <steps-demo :stepsList="stepsList"></steps-demo>
        <div class="body">
          <div class="top">
            <span><i class="el-icon-warning" style="font-size: 14px; color: #0c7ff2"></i>
              已申请过的会议主题，依然可以进行申请！</span>
            <span class="mn_a" @click="dialogMymeet = true">查看我赞助的会议：{{ total }}个</span>
          </div>
          <el-table v-loading="loading" :data="DataTable" ref="multipleTable" style="width: 100%" max-height="520"
            @selection-change="handleSelectionChange">
            <el-table-column type="selection" width="55"> </el-table-column>
            <el-table-column prop="title" label="会议的主题" min-width="200" align="left">
              <template slot-scope="scope">
                <div>
                  <div>
                    <div style="font-weight: bold; color: #202933">
                      {{ scope.row.title }}
                    </div>
                    <div style="margin-top: 10px">
                      {{ scope.row.StartTime }}
                    </div>
                  </div>
                </div>
              </template>
            </el-table-column>
            <el-table-column prop="ztype" label="赞助类型" min-width="120" align="left">
              <template slot-scope="scope">
                <div>
                  <el-select clearable v-model="scope.row.ztype" placeholder="请选择"
                    @change="changeUserAuth(DataTable, scope.$index, scope.row)">
                    <el-option v-for="item in classData" :key="item.value" :label="item.name" :value="item.value">
                    </el-option>
                  </el-select>
                </div>
              </template>
            </el-table-column>
            <el-table-column prop="lyState" label="会议赞助商" min-width="330" align="left">
              <template slot-scope="scope">
                <div class="flex">
                  <img v-for="item in scope.row.sponsorList.slice(0, 9)" :key="item.webinarCompanyAccount"
                    :src="item.webinar_company_logo" class="table_logo" alt="" />
                </div>
              </template>
            </el-table-column>
          </el-table>
        </div>
        <div class="btm_butn" v-if="setpData.stepExamineOneStatus == 1 || setpData.stepExamineOneStatus == 2">
          <el-button type="primary" @click="submitMetting()">提交赞助申请</el-button>
        </div>
        <div class="btm_butn" v-if="setpData.stepExamineOneStatus == 3">
          <el-button type="danger" @click="submitMetting()">重新提交赞助申请</el-button>
        </div>
      </div>
    </div>
    <el-dialog title="我申请的会议主题" :visible.sync="dialogMymeet">
      <el-table :data="myMeetingData">
        <el-table-column property="title" label="会议主题" min-width="250"></el-table-column>
        <el-table-column property="ztype" label="赞助类型" min-width="100"></el-table-column>
        <el-table-column property="createDate" label="申请时间" min-width="150"></el-table-column>
        <el-table-column property="state" label="赞助状态"></el-table-column>
      </el-table>
    </el-dialog>
  </div>
</template>
  
<script>
import applyLeft from "../compontents/left.vue";
import stepsDemo from "../compontents/Steps.vue";
import api from "@/api/index";
import { changeDateFormat } from "@/utils/commin";
export default {
  components: {
    applyLeft,
    stepsDemo,
  },
  data() {
    return {
      DataTable: [],
      stepsList: ["选择赞助的主题", "选择赞助的方式", "提交赞助申请"],
      loading: false,
      dialogMymeet: false,
      myMeetingData: [],
      chooseOnedata: [],
      total: 0,
      setpData: {
        step: 1,
        stepExamineOneStatus: 1,
        stepExaminetwoStatus: 1,
      },
      message: '',
      meetingData: {
        meetinginfo: {
          meetingImg: "",
        },
      },

      rootData: {
        meetingTitle: ''
      },
      classData: [
        { name: "钻石赞助", value: 4 },
        { name: "金牌赞助", value: 1 },
        { name: "银牌赞助", value: 5 },
        // { name: "金牌赞助", value: 3 },
      ],
    };
  },
  mounted() {
    this.getSponsorMeetingInfo();
    this.getCanSponsorSubject();
    //this.getSponsorMeetingAuthories();
    this.getMySponsorMeeting();
    if (this.$route.query.id) {
      this.getSponsorState()
    }

  },
  methods: {
    async getSponsorState() {
      let form = {
        imshowId: this.$store.getters.imShowId,
        id: this.$route.query.id
      }
      const { data } = await api.support.getSponsorState(form)
      if (data.state == 0) {
        this.setpData.stepExamineOneStatus = 2
      } else {
        this.setpData.stepExamineOneStatus = 3
      }
      this.message = data.message
    },
    submitMetting() {
      if (this.chooseOnedata.length == 0) {
        this.$message({ type: 'error', message: '请选择赞助主题！' })
        return false
      }
      if (this.chooseOnedata[0].ztype == '' || this.chooseOnedata[0].ztype == null) {
        this.$message({ type: 'error', message: '请选择赞助类型！' })
        return false
      }
      let form = {
        imshowId: this.$store.getters.imShowId,
        mid: this.chooseOnedata[0].mid,
        parentId: this.$route.query.mid,
        ztype: this.chooseOnedata[0].ztype
      }
      api.support.applySponsor(form).then(res => {
        this.$message({ type: 'success', message: '申请成功，请等待审核！' })
        this.$router.push('/support/index')
      })
    },
    handleSelectionChange(val) {
      if (val.length != 1) {
        this.$message({
          type: "error",
          message: "单次提交只能选取一个会议主题！",
        });
        this.$refs.multipleTable.clearSelection(val[val.length - 1])

      }
      this.chooseOnedata = val
    },
    getMySponsorMeeting() {
      let form = {
        imshowId: this.$store.getters.imShowId,
        mid: this.$route.query.mid,
      };
      api.support.getMySponsorMeeting(form).then((res) => {
        this.myMeetingData = res.data.records;
        if (this.myMeetingData.length > 0) {
          this.myMeetingData.forEach((item) => {
            item.createDate = changeDateFormat(item.createDate);
            switch (item.ztype) {
              case 1:
                item.ztype = "金牌赞助";
                break;
              case 3:
                item.ztype = "金牌赞助";
                break;
              case 4:
                item.ztype = "钻石赞助";
                break;
              case 5:
                item.ztype = "银牌展示";
                break;
              default:
                break;
            }
            switch (item.state) {
              case 0:
                item.state = "赞助审核中";
                break;
              case 1:
                item.state = "赞助审核通过";
                break;
              case 2:
                item.state = "赞助审核驳回";
                break;
              case 3:
                item.state = "撤销赞助申请";
                break;
              case 10:
                item.state = "报告审核中";
                break;
              case 11:
                item.state = "报告审核通过";
                break;
              case 12:
                item.state = "报告审核驳回";
                break;
              case 13:
                item.state = "赞助服务完成";
                break;
              default:
                break;
            }
          });
        }
        this.total = res.data.total;
      });
    },
    changeUserAuth(data, index, row) {
      // data为表格数据源，index为要改变数据的下标，row是要更新的数据
      this.$set(data, index, row);
    },
    async getSponsorMeetingAuthories() {

      //1为0.5天C类会议，2-为1天B类会议，3-为2天A类会议
      let form = {
        imshowId: this.$store.getters.imShowId,
        meetSponsorLevel: this.meetingData.meetinginfo.meetSponsorType,
      };
      const { data } = await api.support.getSponsorMeetingAuthories(form);
      this.rootData = data;
      switch (this.meetingData.meetinginfo.meetSponsorType) {
        case 1:
          this.rootData.meetingTitle = 'C'
          break;
        case 2:
          this.rootData.meetingTitle = 'B'
          break;
        case 3:
          this.rootData.meetingTitle = 'A'
          break;
        default:
          break;
      }
    },
    async getSponsorMeetingInfo() {
      let form = {
        mid: this.$route.query.mid,
      };
      const { data } = await api.support.getSponsorMeetingInfo(form);
      this.meetingData = data;
      this.meetingData.meetinginfo.startTime = changeDateFormat(
        this.meetingData.meetinginfo.startTime
      );
      this.meetingData.meetinginfo.videoEndDate = changeDateFormat(
        this.meetingData.meetinginfo.videoEndDate
      );
      this.getSponsorMeetingAuthories()
    },
    async getCanSponsorSubject() {
      let form = {
        mid: this.$route.query.mid,
      };
      const { data } = await api.support.getCanSponsorSubject(form);
      this.DataTable = data;
    },
    sortChange() { },
  },
};
</script>
  
<style lang="scss" scoped>
.table_logo {
  width: 55px;
  height: 32px;
  display: inline-block;
  padding: 2px 4px;
  border: 1px solid #f0f3f7;
  margin-right: 8px;
  object-fit: contain;
}

.btm_butn {
  padding: 23px;
  border-top: 1px solid #e5eaf0;
  margin-top: 23px;
  text-align: center;
}

.apply_right {
  margin-left: 16px;
  flex-grow: 1;
  width: 50%;

  .apply_root {
    // @include flex(row, center, flex-start);
    background: #e7f2fe;
    border-radius: 2px 2px 2px 2px;
    border: 1px solid #0c7ff2;
    padding: 16px;
    font-size: 14px;
    color: #4f5862;
    line-height: 16px;
    margin-bottom: 16px;

    span {
      color: #0c7ff2;
    }
  }

  .apply_meet_info {
    padding: 13px 16px;
    background: #fff;

    .apply_jg {
      padding: 6px 16px;
      background: #FFEFEB;
      border-radius: 4px 4px 4px 4px;
      color: #4F5862;
      margin: 14px 0;
    }

    h4 {
      font-size: 14px;
      font-weight: 600;
      color: #202933;
      line-height: 16px;
      margin-bottom: 16px;
    }

    .meet_content {
      @include flex(row, flex-start, flex-start);

      .mt_b {
        font-size: 12px;
        font-weight: 600;
        color: #ffffff;
        line-height: 16px;
        padding: 4px 8px;
        background: linear-gradient(90deg, #ffbe31 0%, #ffe485 100%);
        border-radius: 4px 0px 4px 0px;
        position: absolute;
        top: 0;
        left: 0;
      }

      .mt_a {
        font-size: 12px;
        font-weight: 600;
        color: #ffffff;
        line-height: 16px;
        padding: 4px 8px;
        background: linear-gradient(270deg, #ff7272 0%, #f72626 100%);
        border-radius: 4px 0px 4px 0px;
        position: absolute;
        top: 0;
        left: 0;
      }

      .mt_c {
        font-size: 12px;
        font-weight: 600;
        color: #ffffff;
        line-height: 16px;
        padding: 4px 8px;
        background: linear-gradient(90deg, #0ca424 0%, #0dbe29 100%);
        border-radius: 4px 0px 4px 0px;
        position: absolute;
        top: 0;
        left: 0;
      }

      .img {
        width: 177px;
        height: 126px;
        border-radius: 4px 4px 4px 4px;
        display: inline-block;
        margin-right: 24px;
      }

      .content_right {
        .title {
          font-size: 16px;
          font-weight: 600;
          color: #000000;
          line-height: 24px;
          margin-bottom: 10px;
        }

        .time {
          font-size: 14px;
          font-weight: 400;
          color: #4f5862;
          line-height: 19px;
          margin-bottom: 22px;
        }

        .content {
          font-size: 14px;
          color: #7e8790;
          line-height: 24px;
          height: 48px;
        }
      }
    }
  }

  .apply_body {
    background: #fff;
    margin-top: 16px;

    .body {
      border-top: 1px solid #f0f3f7;
      padding: 20px;

      .top {
        padding-bottom: 19px;
        @include flex(row, center, space-between);

        .mn_a {
          display: inline-block;
          color: #0c7ff2;
          text-decoration: underline;
          cursor: pointer;
        }
      }
    }
  }
}
</style>